package com.jsls.netspri.controller.detection;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import net.sf.json.JSONArray;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;




import com.jsls.netspri.dao.SingleDataDao;
/*import com.jsls.netspri.dao.SingleDataDao;*/
import com.jsls.netspri.entity.SingleData;

@Controller
@RequestMapping("/detection")
public class DetectionController {

	@Resource
	private SingleData singleData;
	@Resource
	private SingleDataDao dataDao;
	
	//转到检测界面
	@RequestMapping(value="/singlechannel",method=RequestMethod.GET)
	public String tosingleChannelPage(){
		
		return "detection/singlechannel";
	}
	
	//上传检测数据
	@ResponseBody
	@RequestMapping(value="/singlechannel/upload",method=RequestMethod.POST)
	public boolean singleChannelUpload(@RequestParam(value="uploaddata")String jsondata,@RequestParam(value="id")int id){
		
		//System.out.println(obj.toString());
	//	List<Double> data = getJsonToDoubleList(obj.toString());
		/*for(double e:varray_data){
			System.out.println(e);
		}*/
		 
		singleData.setData(jsondata);
	
		singleData.setUser_id(id);
		
		try{
			dataDao.save(singleData);
			return true;
			}catch (Exception e){
				
				return false;
			}
		
				
		/*return true;*/
		
	}
	
	 /*public static List<Double> getJsonToDoubleList(String str) {
		            JSONArray jsonArray = JSONArray.fromObject(str);
		            List<Double> list=new ArrayList<Double>();
		            for(int i=0;i<jsonArray.size();i++){
		                list.add(jsonArray.getDouble(i));
		           }
		            return list;
		      }
	*/
	
}
